//
//  IDCardCertificationTwoController.m
//  OnionHome
//
//  Created by fengjie on 2019/10/2.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "IDCardCertificationTwoController.h"
#import "OnionCertificationTwoController.h"
#import "CustomCameraController.h"

@interface IDCardCertificationTwoController ()
/**<#属性#>*/
@property (nonatomic,strong)UITextField*nameTexField;
/**<#属性#>*/
@property (nonatomic,strong)UITextField*cardNumTexField;
/**<#属性#>*/
@property (nonatomic,strong)UITextField*industryTexField;

/**<#属性#>*/
@property (nonatomic,strong)UIImageView*leftImage;
/**<#属性#>*/
@property (nonatomic,strong)UIImageView*rightImage;

@end

@implementation IDCardCertificationTwoController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"身份认证";
    [self createUI];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setNavBarBackgroundAndNotClearColor];
}
-(void)leftAction{
    CustomCameraController * vc = [CustomCameraController new];
    [self.navigationController presentViewController:[[BasseNavigationController alloc]initWithRootViewController:vc] animated:YES completion:nil];
    kWeakSelf(weakSelf);
    vc.rentunBlock = ^(UIImage * _Nonnull image) {
        if (image) {
            weakSelf.leftImage.hidden =NO;
            weakSelf.leftImage.image = image;
        }
    };
}
-(void)rightAction{
    CustomCameraController * vc = [CustomCameraController new];
    [self.navigationController presentViewController:[[BasseNavigationController alloc]initWithRootViewController:vc] animated:YES completion:nil];
    kWeakSelf(weakSelf);
    vc.rentunBlock = ^(UIImage * _Nonnull image) {
        if (image) {
            weakSelf.rightImage.hidden = NO;
            weakSelf.rightImage.image = image;
        }
    };
}
-(void)createUI{
    UIButton * bottomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [bottomBtn setBackgroundImage:IMAGE_NAMED(@"guanzhu_bg") forState:UIControlStateNormal];
    [bottomBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [self.view addSubview:bottomBtn];
    kWeakSelf(weakSelf);
    [bottomBtn addActionHandler:^{
        [weakSelf.navigationController pushViewController:[OnionCertificationTwoController new] animated:YES];
    }];

    [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    
    UIView * oneView = [self createView:self.nameTexField LeftName:@"真实姓名"];
    UIView * twoView = [self createView:self.cardNumTexField LeftName:@"身份证号"];
    UIView * thereView = [self createView:self.industryTexField LeftName:@"所在行业"];
    
    UIView * lineView = UIView.new;
    lineView.backgroundColor = UIColorFromRGB(0xF5F7F5);
    UILabel * label = UILabel.new;
    label.textColor = UIColorFromRGB(0x273323);
    label.font = SYSTEMFONT(18);
    label.text = @"上传身份证明(仅用于头条认证)";
    
    UIView * leftView = [self createButtonView:@"手持身份证照片"];
    [leftView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftAction)]];
    UIView * rightView = [self createButtonView:@"身份证正面照片"];
    [rightView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(rightAction)]];

    [self.contenView addSubview:oneView];
    [self.contenView addSubview:twoView];
    [self.contenView addSubview:thereView];
    [self.contenView addSubview:lineView];
    [self.contenView addSubview:label];
    [self.contenView addSubview:leftView];
    [self.contenView addSubview:rightView];
    [self.contenView addSubview:self.leftImage];
    [self.contenView addSubview:self.rightImage];


    [oneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];

    [twoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(oneView);
        make.top.mas_equalTo(oneView.mas_bottom);
    }];
    [thereView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(oneView);
        make.top.mas_equalTo(twoView.mas_bottom);
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(8);
        make.top.mas_equalTo(thereView.mas_bottom);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(lineView.mas_bottom).offset(16);
    }];
    CGFloat  width = (KScreenWidth - 43)/2;
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(label.mas_bottom).offset(16);
        make.width.height.mas_equalTo(width);
        make.bottom.mas_equalTo(-30);
    }];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(label.mas_bottom).offset(16);
        make.width.height.mas_equalTo(width);
        make.bottom.mas_equalTo(-30);
    }];
    [self.leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(leftView);
    }];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(rightView);
    }];

}
-(UIView *)createView:(UITextField *)textfile LeftName:(NSString *)name{
    
    
    UIView * view = UIView.new;
    
    UIView * lineView = UIView.new;
    lineView.backgroundColor = UIColorFromRGB(0xE9EEE7);
    
    UILabel * label = UILabel.new;
    label.textColor = UIColorFromRGB(0x273323);
    label.font = SYSTEMFONT(18);
    label.text = name;
    
    [view addSubview:label];
    [view addSubview:textfile];
    [view addSubview:lineView];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(textfile);
        make.width.mas_equalTo(80);
    }];
    [textfile mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.mas_equalTo(0);
        make.left.mas_equalTo(label.mas_right).offset(10);
        make.height.mas_equalTo(50);
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
        make.top.mas_equalTo(textfile.mas_bottom).offset(0);
    }];
    
    return view;
}
-(UIView *)createButtonView:(NSString *)placeholderName{
    UIView * view = UIView.new;
    view.userInteractionEnabled = YES;
    view.backgroundColor = UIColorFromRGB(0xF5F5F5);
    
    UIImageView * image = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"add_image")];
    image.userInteractionEnabled = YES;
    
    UILabel * label = UILabel.new;
    label.textColor = UIColorFromRGB(0x99A29B);
    label.font = SYSTEMFONT(14);
    label.textAlignment = NSTextAlignmentCenter;
    label.text = placeholderName;
    label.userInteractionEnabled = YES;

    [view addSubview:image];
    [view addSubview:label];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(-10);
        make.width.height.mas_equalTo(45);
    }];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(image.mas_bottom).offset(12);
    }];
    
    
    
    return view;
}
-(UITextField*)nameTexField{
    if(!_nameTexField){
        _nameTexField=[UITextField new];
        _nameTexField.placeholder = @"请输入真实姓名";
    }
    return _nameTexField;
}
-(UITextField*)cardNumTexField{
    if(!_cardNumTexField){
        _cardNumTexField=[UITextField new];
        _cardNumTexField.placeholder = @"请输入真实身份证号码";
    }
    return _cardNumTexField;
}
-(UITextField*)industryTexField{
    if(!_industryTexField){
        _industryTexField=[UITextField new];
        _industryTexField.placeholder = @"请输入你所在行业";
    }
    return _industryTexField;
}
-(UIImageView*)leftImage{
    if(!_leftImage){
        _leftImage=UIImageView.new;
        _leftImage.hidden=YES;
    }
    return _leftImage;
}
-(UIImageView*)rightImage{
    if(!_rightImage){
        _rightImage=UIImageView.new;
        _rightImage.hidden= YES;
    }
    return _rightImage;
}

@end
